<template>
    <div>
        <TrainPage
            ref="TrainPageRef"
            :searchConfig="searchConfig"
            :tableConfig="tableConfig"
            sendUrl="get_bn_statisticscs"
            customize
        >
        </TrainPage>
    </div>
</template>

<script>
export default {
    name: 'admin_bn_user_list',
    data() {
        return {
            searchConfig: [
                {
                    label: '分类',
                    type: 'select',
                    modelName: 'type',
                    options: async () => {
                        return this.bn_create_type_options
                    },
                },
                {
                    label: '用户',
                    type: 'select',
                    modelName: '_user_id',
                    options: async () => {
                        return new Promise((resolve) => {
                            this.$apis
                                .get_authors({
                                    page: 1,
                                    limit: 50,
                                    cache: true,
                                    expire_time: 3600 * 1000,
                                })
                                .then((res) => {
                                    const result = res.data.data.map((item) => {
                                        return {
                                            label: item.username,
                                            value: item._id,
                                        }
                                    })

                                    resolve(result)
                                })
                        })
                    },
                },
            ],
            tableConfig: {
                isSelection: false,
                maxHeightFlag: false,
                stripe: true,
                filterData: (data) => {
                    return data.map((item) => {
                        let { update_time, create_time, user_id,type } = item
                        return {
                            ...item,
                            _create_time: this.klDateFormat(create_time),
                            _update_time: this.klDateFormat(update_time),
                            _author_name: user_id?.username,
                            _type:this.bn_create_type_options.find(item=>item.value==type)?.label
                        }
                    })
                },
                columnObj: [
                    {
                        label: '合成人',
                        props: '_author_name',
                        width: 200,
   
                    },
                    {
                        label: '分类',
                        props: '_type',
                        width: 200,
   
                    },
                    {
                        label: '启动浏览器用时',
                    
                        props: 'bn_s_time1',
                    },
                    {
                        label: '页面打开用时',
                    
                        props: 'bn_s_time2',
                    },
                    {
                        label: '合成用时',
                   
                        props: 'bn_s_time3',
                    },
                    {
                        label: '总用时',
                 
                        props: 'bn_s_time4',
                    },
                    {
                        label: '创建时间',
                        width: 200,
                        props: '_create_time',
                    },
                    {
                        label: '更新时间',
                        width: 200,
                        props: '_update_time',
                    },
                    {
                        label: '操作',
                        slot: 'projectDetail',
                        props: 'action',
                        lock: true,
                        fixed: 'right',
                        children: [
                            {
                                label: '编辑',
                                type: 'success',
                                clickFn: ({ _id = '' }) => {
                                    const { name } = this.$route
                                    if (name === 'my_bn_list') {
                                        this.goTo('/admin/tool/edit', {
                                            query: {
                                                _id,
                                            },
                                        })
                                        return
                                    }
                                    this.$emit('change', {
                                        page: 'edit',
                                        _id,
                                    })
                                },
                            },
                            {
                                label: '删除',
                                type: 'danger',
                                clickFn: async ({ _id } = {}) => {
                                    try {
                                        const res1 = await this.$confirm(
                                            '确认删除这条记录吗,删除后将无法恢复',
                                        ).catch(() => {
                                            return false
                                        })
                                        if (!res1) return
                                        const res = await this.$apis.del_bn_statisticsc({ _id })
                                        this.$message.success(res.msg)
                                        this.initTable()
                                    } catch (err) {
                                        this.Toast(err)
                                    }
                                },
                            },
                        ],
                    },
                ],
            },

            rowCopy: {},
            visable: false,
        }
    },
    computed: {
        ...Vuex.mapGetters(['bn_create_type_options']),
    },
    methods: {
        openDialog(row = {}) {
            this.rowCopy = this.deepCopy(row)
            this.visable = true
        },
    },
}
</script>
